﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aulac.Srv.Db.Common;
using Aulac.Rsc.Ems;
using Aulac.Rsc.Ems.Tags;
using Aulac.Global.Common;

namespace Aulac.Srv.Db.Data.Ems.MdcFiles.PntLogs
{
    partial class EndExamMng
    {
        private void SetPntEndOutsideExamDb(string pOutsideExamPrkID, bool pIsActive)
        {

            sqlQuery = SqlHelper.CreateSqlUpdate(TableNames.MdcFile_OutsideExamHeader, tagMdcFiles.Exam.IsActive);
            sqlQuery += string.Format(" WHERE ({0} = ?)", tagMdcFiles.Exam.OutsideExamPrkID);
            DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery, pIsActive, pOutsideExamPrkID); 
        }
        
        private void SetPntEndOutsideExamDb(string pMdcFilePrkID, string pHspInNum, bool pIsActive)
        {

            sqlQuery = SqlHelper.CreateSqlUpdate(TableNames.MdcFile_OutsideExamHeader, tagMdcFiles.Exam.IsActive);
            sqlQuery += string.Format(" WHERE ({0} = ?) AND ({1} = ?)", tagMdcFiles.Exam.MdcFilePrkID, tagMdcFiles.MdcFiles.HspInNum);
            DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery, pIsActive, pMdcFilePrkID, pHspInNum);
        }

        private void SetPntEndMdcFileDb(string pMdcFilePrkID, bool pIsActive)
        {

            sqlQuery = SqlHelper.CreateSqlUpdate(TableNames.MdcFile_PntExam, tagMdcFiles.Exam.IsActive);
            sqlQuery += string.Format(" WHERE ({0} = ?)", tagMdcFiles.MdcFiles.MdcFilePrkID);
            DbDataProvider.ExecuteNonQuery(ref mDbCmd, sqlQuery, pIsActive, pMdcFilePrkID);
        }

        private bool IsPntCureActiveDb(string pMdcFilePrkID)
        {
            sqlQuery = string.Format("SELECT TOP 1 {0} FROM {1}", tagMdcFiles.MdcFiles.IsActive, TableNames.MdcFile_PntCure);
            sqlQuery += string.Format(" WHERE ({0} = 1) AND ({1} = ?)", tagMdcFiles.MdcFiles.IsActive, tagMdcFiles.MdcFiles.MdcFilePrkID);
            return ValueHelper.isEmpty( DbDataProvider.ExecuteScalar(mDbCmd, sqlQuery, pMdcFilePrkID)) != null;
        }
    }
}
